import { measurementHttp } from '/@/utils/http/axios';
import {
  onlineUserParam,
  onlineUserItems,
  totalUserItems,
  totalUserParam,
  tenantItem,
  appItem,
} from './model/userStatisticModel';

enum Api {
  GET_OLINE_USER_STATISTIC_LIST = '/v1/measurement/user/onlineUser',
  GET_TOTAL_USER_STATISTIC_LIST = '/v1/measurement/user/totalUser',
  GET_TENANT_LIST = '/v1/measurement/user/tenantList',
  GET_APP_LIST = '/v1/measurement/user/appList',
}
export const getOnlineUserStatisticList = async (params: onlineUserParam) => {
  const res = await measurementHttp.post<onlineUserItems[]>({ url: Api.GET_OLINE_USER_STATISTIC_LIST, params });

  const result = res.map((resItem) => {
    resItem.ocCountList = resItem.onlineCountList.map((ocItem) => {
      return {
        name: ocItem.appName,
        data: ocItem.countList,
        type: 'line',
        smooth: false,
      };
    });
    return resItem;
  });

  return result;
};

//上方form中的租户列表
export const getTenantList = async () => {
  const res = await measurementHttp.get<tenantItem[]>({ url: Api.GET_TENANT_LIST });

  const result = res.map((item) => {
    return {
      label: item.tenantName,
      value: item.tenantCode,
    };
  });

  return result;
};
//上方form中的应用列表
export const getAppList = async () => {
  const res = await measurementHttp.get<appItem[]>({ url: Api.GET_APP_LIST });

  const result = res.map((item) => {
    return {
      label: item.appName,
      value: item.appId,
    };
  });

  return result;
};

export const getTotalUserStatisticList = async (params: totalUserParam) => {
  const res = await measurementHttp.post<totalUserItems[]>({ url: Api.GET_TOTAL_USER_STATISTIC_LIST, params });
  res.map((resItem) => {
    resItem.tcCountList = [
      {
        data: resItem.totalCountList,
        type: 'line',
        smooth: false,
      },
    ];
    return resItem;
  });
  return res;
};
